/*
 * @lc app=leetcode.cn id=206 lang=java
 *
 * [206] 反转链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode reverseList(ListNode head) {

        System.out.println("head:"+(null!=head?head.val:null));

        if(null==head || head.next==null) return head;

        ListNode next = head.next;
        ListNode reversedHead = reverseList(next);

        System.out.println("reversedHead:"+(null!=head?reversedHead.val:null));
        System.out.println("head:"+head.val+",next:"+(null==next ? null : next.val)+",next.next:"+(null==next||null==next.next ? null : next.next.val));
        // head.next = next.next;
        //交换
        head.next = null;
        next.next = head;
        return reversedHead;
    }
}
// @lc code=end

